﻿Public Class UserList
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.Page.User.IsInRole("Admin") Then
            Response.Redirect("User.aspx")
        End If

        If ((Request.QueryString("sc") Is Nothing) Or (Request.QueryString("sv") Is Nothing)) Then
            populateList("", "")
        Else
            populateList(Request.QueryString("sc"), Request.QueryString("sv"))
        End If

    End Sub

    Protected Sub btn_Search_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_Search.Click

        Dim searchColumn As String = dd_Search.SelectedValue
        Dim searchValue As String = tb_Search.Text

        Response.Redirect("UserList.aspx?sc=" + searchColumn + "&sv=" + searchValue)

    End Sub

    Protected Sub populateList(ByVal searchColumn As String, ByVal searchValue As String)

        If (searchValue = "''") Then
            searchValue = ""
        End If

        Dim fillList As String = "SELECT [ID], [UserName], [FirstName], [LastName], [Picture], [Active] FROM [Users] WHERE 1 = 1 "

        If (searchColumn <> "") Then
            fillList = fillList + " AND " + searchColumn + " LIKE '%" + searchValue + "%'"
        End If

        SqlDataSource1.SelectCommand = fillList
        gw_list.DataBind()

    End Sub


End Class